import itchat

itchat.auto_login(hotReload=True)
friends = itchat.get_friends(update=True)
# df_friends = pd.DataFrame(friends)

# for item in df_friends:
#     print(item)
#     print(df_friends[item])

user = friends[0]["NickName"]
print("授权微信用户为："+user)
os.mkdir(user)  # 创建文件夹用于装载所有好友头像
num = 0
for i in friends:
    img = itchat.get_head_img(userName=i["UserName"])
    fileImage = open(user + "/" + i["UserName"] + ".jpg",'wb')
    fileImage.write(img)
    fileImage.close()
    num += 1
print("头像保存完成")